//
//  BSLoginRegisterViewController.m
//  baisibudejie
//
//  Created by 陈博文 on 15/12/20.
//  Copyright © 2015年 陈博文. All rights reserved.
//

#import "BSLoginRegisterViewController.h"
#import "BSInputView.h"
#import "BSFastLoginView.h"

@interface BSLoginRegisterViewController ()
@property (weak, nonatomic) IBOutlet UIView *inputView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *inputViewConstraintX;
@property (weak, nonatomic) IBOutlet UIView *fastLoginView;

@end

@implementation BSLoginRegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //============中间注册=====================
    //登录
    BSInputView *inputView0 = [BSInputView loadLoginView];
    [self.inputView addSubview:inputView0];
    //注册
    BSInputView *inputView1 = [BSInputView loadregisterView];
    [self.inputView addSubview:inputView1];
    
    //===============快速登录==============
    BSFastLoginView *fastLoginView = [BSFastLoginView loadFastLoginView];
    
    [self.fastLoginView addSubview:fastLoginView];
}
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    // ================给inputView赋值========================
    BSInputView *loginView = [self.inputView.subviews firstObject];
    
    // 最好设置frame
    loginView.frame = CGRectMake(0, 0, self.inputView.width * 0.5, self.inputView.height);
    // 设置注册尺寸
    BSInputView *registerView = [self.inputView.subviews lastObject];
    
    registerView.frame = CGRectMake( self.inputView.width * 0.5, 0, self.inputView.width * 0.5, self.inputView.height);
//    NSLog(@"%@",NSStringFromCGRect(self.inputView.frame));
    // ==================设置注册界面尺寸========================
    BSFastLoginView *fastLoginView = [self.fastLoginView.subviews firstObject];
    fastLoginView.frame = self.fastLoginView.bounds;

}


- (IBAction)closeButton:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)registerBuutonClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    _inputViewConstraintX.constant = _inputViewConstraintX.constant == 0? -BSScreenW: 0;
    
    
    [UIView animateWithDuration:0.25 animations:^{
        
        // 为什么要拿到父控件去做约束布局
    //一般做动画都要重新布局
        [self.view layoutIfNeeded];
    }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    // 退下键盘
    [self.view endEditing:YES];
}

@end
